//package top.qitun.controller;
//
//import java.util.Date;
//import java.util.Optional;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.RestController;
//
//import io.swagger.annotations.ApiOperation;
//import io.swagger.annotations.ApiParam;
//import top.qitun.api.ShopServiceAPI;
//import top.qitun.bizz.catalog.catalog.entity.CatalogBO;
//import top.qitun.bizz.catalog.catalog.service.CatalogService;
//import top.qitun.bizz.catalog.product.entity.Product;
//import top.qitun.bizz.catalog.product.entity.ProductBO;
//import top.qitun.bizz.catalog.product.service.ProductService;
//import top.qitun.bizz.shop.ttable.entity.TTableBO;
//import top.qitun.modal.request.ProductCreateRequest;
//import top.qitun.model.response.ObjectCollectionResponse;
//import top.qitun.model.response.ObjectDataResponse;
//import top.qitun.util.OrikaMapper;
//
///**
// * 店铺创建类
// * @author Cloudwei
// *
// */
//@RestController
//@RequestMapping(value = "/v1")
//public class ProductController {
//	Logger logger = LoggerFactory.getLogger(getClass());
//	
//    @Autowired
//    private ProductService productService;
//    
//    @Autowired
//    private ShopServiceAPI shopServiceAPI;
//
//    @ApiOperation(value = "新建菜品", notes = "新建菜品")
//    @RequestMapping(value = "/product", method = RequestMethod.POST)
//    public ObjectDataResponse<Product> create(@RequestBody ProductCreateRequest request) {
//    	String desc = "新建菜品";
//    	try{
//    		Product product=null;
//	    	Date now = new Date();
//	    	product = OrikaMapper.map(request, Product.class);
//	    	product.setCreateTime(now);
//	    	product.setLastUpdaeTime(now);
//	    	productService.add(product);
//		    return new ObjectDataResponse<Product>(0,desc+"成功",product);
//    	}catch(Exception e){
//    		logger.error(desc+"失败",e);
//    		return new ObjectDataResponse<>(-1,desc+"失败.请联系客服"+e.getMessage());
//    	}
//    }
//    
//    @ApiOperation(value = "查询菜品", notes = "查询菜品")
//    @RequestMapping(value = "/product/{id}", method = RequestMethod.GET)
//    public ObjectDataResponse<Product> getProductById(@ApiParam(example = "4",defaultValue="4", value = "菜单Id") @PathVariable(value="id")Integer id) {
//    	String desc = "新建菜品";
//    	try{
//    		Product product= productService.queryById(id);
//		    return new ObjectDataResponse<Product>(0,desc+"成功",product);
//    	}catch(Exception e){
//    		logger.error(desc+"失败",e);
//    		return new ObjectDataResponse<>(-1,desc+"失败.请联系客服"+e.getMessage());
//    	}
//    }
//    
//	@ApiOperation(value = "查询分类下菜品", notes = "查询分类下菜品")
//	@RequestMapping(value = "/product/catalog/{id}", method = RequestMethod.GET)
//	public ObjectCollectionResponse<ProductBO> productListInCatalog(
//			@ApiParam(example = "4",defaultValue="4", value = "菜品Id") @PathVariable(value = "id") Integer catalogId) {
//		String desc = "查询分类下菜品";
//		logger.debug(desc+" start");
//		try {
//			return Optional.ofNullable(productService.queryProductListInCatalog(catalogId))
//					.map((productList) -> new ObjectCollectionResponse<ProductBO>(0,desc+"成功",productList))
//					.orElse(new ObjectCollectionResponse<>(1, desc + "查询为空"));
//		} catch (Exception e) {
//			logger.error(desc + "失败", e);
//			return new ObjectCollectionResponse<>(-1, desc + "失败.请联系客服" + e.getMessage());
//		}
//	}
//	
//	@ApiOperation(value = "查询台号下的菜品", notes = "查询分类下菜品")
//	@RequestMapping(value = "/product/table/{id}", method = RequestMethod.GET)
//	public ObjectCollectionResponse<ProductBO> productListByTableId(
//			@ApiParam(example = "4",defaultValue="4", value = "菜品Id") @PathVariable(value = "id") Integer tableId) {
//		String desc = "查询分类下菜品";
//		logger.debug(desc + " start");
//		try {
//			ObjectDataResponse<TTableBO> tableDataResponse = shopServiceAPI.queryTableById(tableId);
//			// 根据tableId,查出店铺Id,根据店铺id查出该店铺的菜品
//			return Optional
//					.ofNullable(tableDataResponse.getData())
//					.map(response -> response.getShopId())
//					.map(shopId -> productService.queryProductListByShopId(shopId))
//					.map(productList -> new ObjectCollectionResponse<>(1, "成功", productList))
//					.orElse(new ObjectCollectionResponse<>(tableDataResponse.getCode(), tableDataResponse.getMessage()));
//		} catch (Exception e) {
//			logger.error(desc + "失败", e);
//			return new ObjectCollectionResponse<>(-1, desc + "失败.请联系客服" + e.getMessage());
//		}
//	}
//}
